<%@page import="com.sinba.common.utils.TranType"%>
<%@page import="com.sinba.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/transfer.jsp");
	return;
}
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
TransactionRecordDTO trDTO = new TransactionRecordDTO();
trDTO.setLoginName((String)session.getAttribute("loginName"));
trDTO.setTransactionTypes(new String[]{TranType.ZhuanZhang});

int pages = 1;
if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;
trDTO.setStart( start );
trDTO.setLimit( rows );

PageDTO transferPageDTO = transactionRecordService.findTransactionRecordPager(trDTO,"desc","optDate");
if(transferPageDTO!=null){
	transferPageDTO.setPage( pages );
	transferPageDTO.setRows( rows );
}
request.setAttribute("transferPageDTO",transferPageDTO);
session.setAttribute("middle", "财务管理");
session.setAttribute("end", "转账");	
//可提现余额
Double trbalance1 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Dynamic");
request.setAttribute("trbalance1",trbalance1);
/* Double staticBalance = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Static");
request.setAttribute("staticBalance",staticBalance); */

IAccountService acService = (IAccountService)ac.getBean("accountService");
AccountDTO transferDto = acService.findAccountInfo();
request.setAttribute("transferDto",transferDto);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><fmt:message key="i18n.accountZhuanZhang"/>-<fmt:message key="i18n.title"/> </title>
<jsp:include page="common.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="page_head.jsp"></jsp:include>
	
	<div class="row">
		<div class="col-md-12">
			<div class="box border primary">
				<div class="box-title">
					<h4><i class="fa fa-bars"></i><fmt:message key="i18n.accountZhuanZhang"/></h4>
				</div>
				<div class="box-body big">
					<h3 class="form-title"><fmt:message key="i18n.accountZhuanZhang"/></h3>
					<form class="form-horizontal" role="form" id="transfer_form" action="registerUser!userOpt.action" method="post">
							<input type="hidden" name="optType" value="ZhuanZhang" />
							<input type="hidden" name="pageUrl" value="transfer.jsp" />
							<input type="hidden" id="transfer_loginName" name="loginName" value="${session.loginName }" />
					  <div class="form-group">
						<label class="col-sm-3 control-label"><fmt:message key="i18n.dyAccount"/>：</label>
						<div class="col-sm-9">
						  <input type="text" class="form-control" placeholder="<fmt:message key="i18n.dyAccount"/>" 
						  readonly="readonly" value="${trbalance1}">
						</div>
					  </div>
					   <div class="form-group">
							<label class="col-sm-3 control-label"><fmt:message key="i18n.accountBag"/>：</label>
							<div class="col-sm-9">
							 <select class="form-control" name="dtype" >
							 	<option value="Dynamic"><fmt:message key="i18n.dyAccount"/></option>
							 </select>
						  </div>
					  </div>
					  <div class="form-group">
						<label class="col-sm-3 control-label"><fmt:message key="i18n.zhuanruAcount"/>：</label>
						<div class="col-sm-9">
						  <input type="text" id="transfer_transAccount" name="transAccount" class="form-control easyui-validatebox" onBlur="findUserNameByLoginName(this.value,'transfer_userName')" placeholder="<fmt:message key="i18n.piBrankAccount"/>">
						  <span class="tx_contBoxR3_1" id="transfer_userName" style="display: none">*</span>
						</div>
					  </div>
					  
					   <div class="form-group">
						<label class="col-sm-3 control-label"><fmt:message key="i18n.zhuanZhangMoney"/>：</label>
						<div class="col-sm-9">
						  <input type="text" name="value" required="true" class="form-control easyui-validatebox easyui-numberbox" placeholder="<fmt:message key="i18n.zhuanZhangMoney"/>">
						  <span id="transfer_userName" style="display: none;">*</span>
						</div>
					  </div>
					  	<div class="form-group">
						<label class="col-sm-3 control-label"></label>
						<div class="col-sm-9">
							<c:if test="${not empty session.activationTime}">
								<button onclick="checkform('${user.loginName}')" class="btn btn-primary" style="width:15em;"><fmt:message key="i18n.confimzhuanZhang"/></button>
							</c:if>
						</div>
					  </div>
					 </form>
				</div>
			</div>
		</div>
	</div>
	
	<jsp:include page="page_foot.jsp"></jsp:include>  
<script type="text/javascript" src="../scripts/user/common.js"></script>
<script type="text/javascript" src="../scripts/user/reguser.js"></script>
<script>


function checkform(){
	if($('#transfer_transAccount').val()==''){
		alert('转入账号不能为空!');
		$('#transfer_transAccount').focus();
		return false;
	}
	if($('#transfer_value').val()==''){
		alert('转入金额不能为空!');
		$('#transfer_value').focus();
		return false;
	}
	var toMoeny = $('#transfer_value').val()
	if(toMoeny!=''){
		toMoeny = toMoeny.replace(/(^\s*)|(\s*$)/g, ""); 
	}
	var a = /^(\d*|\-?[1-9]{1}\d*)$/;
	if(!toMoeny.match(a) || toMoeny==0){
		alert("转入金额不是正整数!");
		return false;
	}
	if(toMoeny % 10 != 0){
		alert('请输入10的倍数金额!');
		return false;
	}
	/* if($('#transfer_validCode').val()==''){
		alert('验证码不能为空!');
		$('#transfer_validCode').focus();
		return false;
	} */
/* 	if($('#transfer_passwordAnswer').val()==''){
		alert('密保答案不能为空!');
		$('#transfer_passwordAnswer').focus();
		return false;
	} */
	
	$('#transfer_form').submit();
	/**
	$.post('activationCode!authEmailCode.action','dto.type=邮件&dto.category=转账&dto.activationCode='+$('#transfer_validCode').val(),function(res){
		 if(!res){
			 alert('邮箱验证码不正确!');
			 return false;
		 }else{
			 $('#transfer_form').submit();
		 }
	});
	**/
}


</script>
</body>
</html>